package createThread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
 * @program: jvm
 * @description
 * @author: tkk fendoukaoziji
 * @create: 2019-04-09 10:54
 **/
public class TwoThreadDeleteList {
    public static void main(String[] args) {
        Integer[] array = {0, 1, 2, 3};
        ArrayList<Integer> list = new ArrayList<Integer>(Arrays.asList(array));

        ExecutorService executors = Executors.newFixedThreadPool(2);

            while(list.size()>0){
                executors.submit(new MyListThread(list));
            }
            //关闭线程池
        executors.shutdown();
    }
    public static class MyListThread implements Runnable{
        public ArrayList<Integer> list;
        public MyListThread(ArrayList<Integer> list){
            this.list=list;
        }

        public void run() {
            synchronized (list) {
                if (list.size() > 0) {
                    System.out.println(Thread.currentThread().getName() + "is running ");
                    System.out.println("当前list第一个数值" + list.get(0));
                    System.out.println("执行删除");
                    list.remove(list.get(0));
                }
            }
        }
    }
}














